use config::ConfigError;
use serde::Deserialize;

#[derive(Deserialize)]
#[derive(Debug)]
pub struct ServerConfig {
    pub host : String,
    pub port : String,
}

#[derive(Debug,Deserialize)]
pub struct MysqlConfig{
    pub msn:String,
}

#[derive(Deserialize)]
#[derive(Debug)]
pub struct Config {
    pub server : ServerConfig,
    pub db : MysqlConfig,
}

impl Config {
    pub fn  from_env() -> Result<Self , ConfigError> {
        let mut cfg = config::Config::new();
        cfg.merge(config::Environment::new())?;
        cfg.try_into()
    }
}